// ignore_for_file: file_names, slash_for_doc_comments, must_call_super, unnecessary_overrides, override_on_non_overriding_member, must_be_immutable, prefer_const_constructors, sized_box_for_whitespace, avoid_unnecessary_containers, avoid_print

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:mybase/base/abstract/IFFScaffold.dart';
import 'package:mybase/base/widget/layout/FFLineContainer.dart';
import 'package:mybase/base/widget/layout/FFNavi.dart';
import 'package:mybase/base/widget/layout/FFTextButton.dart';
import 'package:mybase/base/widget/page/FFScaffold.dart';
import 'package:mybase/base/animator/FFAnimatorBaseWidget.dart';

class Animator2Page extends FFScaffold {
  String? name;

  Animator2Page({
    Key? key,
    this.name,
  }) : super(key: key);

  @override
  Animator2PageState createState() => Animator2PageState();
}

class Animator2PageState extends FFScaffoldState with MFFScaffold {
  /**固定写法 */
  @override
  IFFScaffold get iffScaffold => this;

  @override
  Animator2Page get widget => super.widget as Animator2Page;

  @override
  // TODO: implement ffPageStatus
  FFPageStatus? get ffPageStatus => FFPageStatus.result;

  /**固定写法end */

  late AnimationController animatedContainer;

  @override
  void ffInitState() {
    super.ffInitState();

    animatedContainer = AnimationController(duration: Duration(milliseconds: 220), vsync: this);
  }

  @override
  void ffDispose() {
    super.ffDispose();
  }

  @override
  Widget? ffNavi(BuildContext context) {
    return FFNaviFast.navi(context, "测试动画FFAnimatorWidget",
        color: Colors.white);
  }

  @override
  Widget? ffBody(BuildContext context) {
    List<Widget> slivers = [
      SliverToBoxAdapter(
        child: FFAnimatorBaseWidget(
          animationController: animatedContainer,
          createAnimation: (controller) {
            Animation<double> curve = CurvedAnimation(parent: controller, curve: Curves.ease);
            return Tween(begin: 0.0, end: 1.0).animate(curve);
          },
          child: (controller, animation) {
            return Container(
              width: 100.w,
              child: FFLineContainer(
                children: [
                  FFTextButton(
                    padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
                    unconstrainedBox: true,
                    text: "动画放大效果",
                    color: Colors.pink,
                    onClick: () {
                      controller.forward();
                    },
                  ),
                  FFTextButton(
                    padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
                    unconstrainedBox: true,
                    text: "动画缩小效果",
                    color: Colors.pink,
                    onClick: () {
                      controller.reverse();
                    },
                  ),
                  Container(
                    width: 100.w,
                    height: 100.w * animation.value,
                    color: Colors.blue,
                    child: CustomScrollView(
                      slivers: [
                        SliverList(
                          delegate: SliverChildBuilderDelegate(
                            (BuildContext ctx, int index) {
                              return Container(
                                height: 50.w,
                                margin: EdgeInsets.only(top: 1.w),
                                color: Colors.red,
                              );
                            },
                            childCount: 2,
                          ),
                        )
                      ],
                    ),
                  ),
                ],
              ),
            );
          },
        ),
      ),
    ];
    return CustomScrollView(slivers: slivers);
  }
}
